package com.shop.controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.shop.service.GoodsService;
import com.shop.service.impl.GoodsServiceImpl;

@WebServlet("/getGoods.do")

public class GetGoodsServlet extends HttpServlet{
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		GoodsService gs = new GoodsServiceImpl();
		int pageNum;
		int pageSize;

		try {
			pageNum = Integer.parseInt(req.getParameter("pageNum"));
		}catch(Exception e){
			pageNum = 1;
		}
		
		try {
			pageSize = Integer.parseInt(req.getParameter("pageSize"));
		}catch(Exception e){
			pageSize = 5;
		}
		
		req.setAttribute("page", gs.getAllGoods(pageNum, pageSize));
		req.getRequestDispatcher("goods.jsp").forward(req, resp);
		
	}
}
